var map;
var pointManager;
var monsterManger;
var tow1;
var tow1_arrow_list = [];

GameState.start = function(game){};
GameState.start.prototype = {

  create: function() {
    this.manager = new LevelManage();
    this.manager.start();

    map = game.add.tilemap(this.manager.getMap());

    map.addTilesetImage('tiles');
    layer = map.createLayer('bg');

    layer.resizeWorld();
    // var cop = game.add.sprite(0, 0, 'playList');
    //cop.frameName = 'toolbg.png';
    var points = map.objects.obj;
    pointManager = new WayPoint(points); 
    monsterManger = new MonsterManager(this.manager, pointManager);

    monsterManger.make();
    game.input.onDown.add(this.showTowerList, this);
  },

  update: function() {
    if (tow1_arrow_list.length > 0) {
      for(var i = 0, len = tow1_arrow_list.length; i < len; i++) {
        tow1_arrow_list[i].update();
      }
      
    }
  },

  showTowerList: function() {
    var currentTile = map.getTile(layer.getTileX(game.input.activePointer.worldX), layer.getTileY(game.input.activePointer.worldY));
    if (currentTile.index == 24) {
      console.log(currentTile);
      currentTile.index = 8;
      this.addTower(currentTile.worldX, currentTile.worldY);
    }
  },

  addTower: function(x, y) {
    var tow1_arrow = new FreezeTower(x, y, monsterManger);
    tow1_arrow_list.push(tow1_arrow);
  }

}

